package web.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;
import org.jose4j.lang.JoseException;

import com.jfinal.aop.Before;

import kit.token.TokenBuilder;
import web.common.BaseController;
import web.interceptor.JwtInterceptor;

public class JwtController extends BaseController {
	/**
	* @Title: index
	* @Description: 验证提交数据
	* @author yangyw
	* @throws
	*/
	@Before(JwtInterceptor.class)
	public void index() {
		Map<String, String> data = getAttr("data");
		renderJson(data);
	}

	/**
	* @Title: generate
	* @Description: 生成提交数据
	* @author yangyw
	* @throws
	*/
	public void generate() {
		Map<String, Object> claimMap = new HashMap<>();
		claimMap.put("id", 123);
		claimMap.put("name", "yangyw");
		claimMap.put("sex", "男");
		String authorization;
		try {
			authorization = TokenBuilder.generate(DigestUtils.md5Hex("apikey"), claimMap);
			renderJson(authorization);
		} catch (JoseException e) {
			e.printStackTrace();
		}
	}
}
